<?php

namespace app\common\library\wanshun;
use think\Cache;

/**
 * 基因扣模块
 * Class Kuaidi100
 * @package app\common\library\express
 */
class Jik
{
    /* @var array $config 基因扣配置 */
    private $config;

    /* @var string $error 错误信息 */
    private $error;

    /**
     * 构造方法
     * WxPay constructor.
     * @param $config
     */
    public function __construct()
    {
        $this->config = [];
        $this->config['api_url'] = 'http://career.jiyinkou.com/';
        $this->config['api_token'] = '11ecbc307d28e050cae5655fac13d910';
    }

    //订单-------------------------------------------------------------------------------------->
    //搜索订单
    public function ordersearch($param)
    {

        $path = $this->config['api_url'];
        $url = $path.'/api/wanshun/db03/order/search'; 

        //p($url);

        $param = urldecode(json_encode([
            'data'=>$param,
            'signature'=>$this->config['api_token'],
        ],JSON_UNESCAPED_UNICODE));

        //p($param);

        $result = json_decode(curlPostJson($url,$param),true) ;

        //p($result);

        //die();

        if($result['code'] != 200){
            $this->error = $result['code'].'-'.$result['msg'];
            return false;
        }

        if(isset($result['data']) && !empty($result['data'])){
            return $result['data'];
        }else{
            return [];
        }

    }
    //更新订单
    public function orderset($param)
    {

        $path = $this->config['api_url'];
        $url = $path.'/api/wanshun/db03/order/set/orders'; 

        //p($url);

        $param = urldecode(json_encode([
            'data'=>$param,
            'signature'=>$this->config['api_token'],
        ],JSON_UNESCAPED_UNICODE));

        //p($param);

        $result = json_decode(curlPostJson($url,$param),true) ;

        //p($result);

        if($result['code'] != 200){
            $this->error = $result['code'].'-'.$result['msg'];
            return false;
        }

        return true;

    }
    




    //调度车-------------------------------------------------------------------------------------->
    //搜索可调度车辆
    public function getdiaoduche($param)
    {

        $path = $this->config['api_url'];
        $url = $path.'/api/wanshun/db03/order/cayuing/search'; 

        //p($url);

        $param = urldecode(json_encode([
            'data'=>$param,
            'signature'=>$this->config['api_token'],
        ],JSON_UNESCAPED_UNICODE));

        //p($param);

        $result = json_decode(curlPostJson($url,$param),true) ;

        //p($result);

        //die();

        if($result['code'] != 200){
            $this->error = $result['code'].'-'.$result['msg'];
            return false;
        }

        return $result['data'];

    }
    //设置可调度车辆
    public function setdiaoduche($param)
    {

        $path = $this->config['api_url'];
        $url = $path.'/api/wanshun/db03/order/cayuing/set/groupid'; 

        //p($url);

        $param = urldecode(json_encode([
            'data'=>$param,
            'signature'=>$this->config['api_token'],
        ],JSON_UNESCAPED_UNICODE));

        //p($param);

        $result = json_decode(curlPostJson($url,$param),true) ;

        //p($result);

        if($result['code'] != 200){
            $this->error = $result['code'].'-'.$result['msg'];
            return false;
        }

        return true;

    }

    //添加可调度车辆
    public function adddiaoduche($param)
    {
        $path = $this->config['api_url'];
        $url = $path.'/api/wanshun/db03/order/cayuing/add'; 

        //p($url);
        $param = urldecode(json_encode([
            'data'=>$param,
            'signature'=>$this->config['api_token'],
        ],JSON_UNESCAPED_UNICODE));

        //p($param);
        $result = json_decode(curlPostJson($url,$param),true) ;
        //p($result);
        //die();

        if($result['code'] != 200){
            $this->error = $result['code'].'-'.$result['msg'];
            return false;
        }

        return true;
    }


    //承运单-------------------------------------------------------------------------------------->
    public function getchengyunorder($param)
    {

        $path = $this->config['api_url'];
        $url = $path.'/api/wanshun/db03/order/caying/search'; 

        //p($url);

        $param = urldecode(json_encode([
            'data'=>$param,
            'signature'=>$this->config['api_token'],
        ],JSON_UNESCAPED_UNICODE));

        //p($param);

        $result = json_decode(curlPostJson($url,$param),true) ;

        //p($result);

        if($result['code'] != 200){
            $this->error = $result['code'].'-'.$result['msg'];
            return false;
        }
        return $result['data'];
    }
    //添加承运单
    public function addchengyunorder($param)
    {
        $path = $this->config['api_url'];
        $url = $path.'/api/wanshun/db03/order/caying/add'; 

        //p($url);
        $param = urldecode(json_encode([
            'data'=>$param,
            'signature'=>$this->config['api_token'],
        ],JSON_UNESCAPED_UNICODE));

        //p($param);
        $result = json_decode(curlPostJson($url,$param),true) ;
        //p($result);
        //die();

        if($result['code'] != 200){
            $this->error = $result['code'].'-'.$result['msg'];
            return false;
        }

        return true;
    }
    //获取承运单费用
    public function getchengyunorderprice($param)
    {

        $path = $this->config['api_url'];
        $url = $path.'/api/wanshun/db03/order/caypurchg/search'; 

        //p($url);

        $param = urldecode(json_encode([
            'data'=>$param,
            'signature'=>$this->config['api_token'],
        ],JSON_UNESCAPED_UNICODE));

        //p($param);

        $result = json_decode(curlPostJson($url,$param),true) ;

        //p($result);

        if($result['code'] != 200){
            $this->error = $result['code'].'-'.$result['msg'];
            return false;
        }
        return $result['data'];
    }
    //添加承运单费用
    public function addchengyunorderprice($param)
    {
        $path = $this->config['api_url'];
        $url = $path.'/api/wanshun/db03/order/caypurchg/add'; 

        //p($url);
        $param = urldecode(json_encode([
            'data'=>$param,
            'signature'=>$this->config['api_token'],
        ],JSON_UNESCAPED_UNICODE));

        //p($param);
        $result = json_decode(curlPostJson($url,$param),true) ;
        //p($result);
        //die();

        if($result['code'] != 200){
            $this->error = $result['code'].'-'.$result['msg'];
            return false;
        }

        return true;
    }
    

    //承运商-------------------------------------------------------------------------------------->
    //承运商分类
    public function getchengyunfl()
    {

        $path = $this->config['api_url'];
        $url = $path.'/api/wanshun/db03/supplier/kind/search'; 

        //p($url);

        $param = [
            'page_index' => 1,       // 页数
            'page_size' => 1000       // 每页数量
        ];

        $param = urldecode(json_encode([
            'data'=>$param,
            'signature'=>$this->config['api_token'],
        ],JSON_UNESCAPED_UNICODE));

        //p($param);

        $result = json_decode(curlPostJson($url,$param),true) ;

        //p($result);

        if($result['code'] != 200){
            $this->error = $result['code'].'-'.$result['msg'];
            return false;
        }
        return $result['data'];
    }

    //承运商
    public function getchengyunshang($param)
    {

        $path = $this->config['api_url'];
        $url = $path.'/api/wanshun/db03/supplier/search'; 

        //p($url);

        $param = urldecode(json_encode([
            'data'=>$param,
            'signature'=>$this->config['api_token'],
        ],JSON_UNESCAPED_UNICODE));

        //p($param);

        $result = json_decode(curlPostJson($url,$param),true) ;

        //p($result);

        //die();

        if($result['code'] != 200){
            $this->error = $result['code'].'-'.$result['msg'];
            return false;
        }
        return $result['data'];
    }

    //费用类型----------------------------------------->
    public function getpricetype()
    {

        $path = $this->config['api_url'];
        $url = $path.'/api/wanshun/db03/account/payitem/search'; 

        //p($url);

        $param = [
            'page_index' => 1,       // 页数
            'page_size' => 10000       // 每页数量
        ];

        $param = urldecode(json_encode([
            'data'=>$param,
            'signature'=>$this->config['api_token'],
        ],JSON_UNESCAPED_UNICODE));

        //p($param);

        $result = json_decode(curlPostJson($url,$param),true) ;

        //p($result);

        if($result['code'] != 200){
            $this->error = $result['code'].'-'.$result['msg'];
            return false;
        }
        return $result['data'];
    }







    public function baseapi($param)
    {

        $path = $this->config['api_url'];
        $url = $path.'/api/wanshun/db03/'.$param['action']; 

        //p($url);

        $params = [
            'page_index' => $param['page_index'],       // 页数
            'page_size' => $param['page_size']     // 每页数量
        ];

        //p($param);

        if(isset($param['extra_where']) && !empty($param['extra_where'])){
            foreach ($param['extra_where'] as $key => $value) {
                if(count($value) == 2){
                    $params[$value[0]] = $value[1];
                }else if(count($value) == 3){
                    $params['filter'][] = $value;
                }
            }
        }

        $params = urldecode(json_encode([
            'data'=>$params,
            'signature'=>$this->config['api_token'],
        ],JSON_UNESCAPED_UNICODE));

        //p($params);

        //

        $result = json_decode(curlPostJson($url,$params),true) ;

        //p($result);
        //die();
        

        if($result['code'] != 200){
            $this->error = $result['code'].'-'.$result['msg'];
            return false;
        }
        return $result['data'];
    }
    
    
    public function baseseveapi($param)
    {


        $path = $this->config['api_url'];
        $url = $path.'/api/wanshun/db03/'.$param['dicargs']['action']; 
        p($url);

        $param = urldecode(json_encode([
            'data'=>$param,
            'signature'=>$this->config['api_token'],
        ],JSON_UNESCAPED_UNICODE));

        p($param);

        $result = json_decode(curlPostJson($url,$param),true) ;

        p($result);

        if($result['code'] != 200){
            $this->error = $result['code'].'-'.$result['msg'];
            return false;
        }
        return true;
    }

    
    

    
    




    

    /**
     * 返回错误信息
     * @return string
     */
    public function getError()
    {
        return $this->error;
    }

}